<?php
/**
 * Created by PhpStorm.
 * User: coolinmind
 * Date: 24/01/2019
 * Time: 12:02
 */

namespace App\Services\UCenter;


use App\Services\UCenter\UCenter\WayBillLogic;

class WayBill
{
    /**
     * 车主接单（形成运单）
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function createPrivateWayBill($data)
    {
        $data = pick_array($data, ['user_id', 'cargo_id','car_card', 'role_ids','driver','phone']);
        ValidateWayBill::checkValidate($data, ['user_id', 'cargo_id']);
        return (new WayBillLogic())->createPrivateWayBill($data);
    }

    /**
     * 车主接单（形成运单）
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function createCompanyWayBill($data)
    {
        $data = pick_array($data, ['user_id', 'cargo_id','car_card','driver','phone','assit_driver','assit_phone','driver_id']);
        ValidateWayBill::checkValidate($data, ['user_id', 'cargo_id','phone']);
        return (new WayBillLogic())->createCompanyWayBill($data);
    }

    /**
     * 根据id获取运单详情
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function getWayBillDetail($data)
    {
        $data = pick_array($data, ['id', 'role_ids']);
        ValidateWayBill::checkValidate($data, ['id', 'role_ids']);
        return (new WayBillLogic())->getWayBillDetail($data);
    }

    /**
     * 根据user_id获取车辆与司机
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function getCompanyCarAndDriver($data)
    {
        $data = pick_array($data, ['user_id']);
        ValidateWayBill::checkValidate($data, ['user_id']);
        return (new WayBillLogic())->getCompanyCarAndDriver($data);
    }

    /**
     * 添加订阅路线
     * @param $data
     * @return mixed
     * @throws \App\Exceptions\RequestFailException
     */
    public function addSubscription($data)
    {
        $data = pick_array($data, ['start_addr', 'end_addr', 'user_id', 'start_city_id', 'end_city_id','start_county_id','end_county_id']);
        ValidateWayBill::checkValidate($data, ['start_addr', 'end_addr', 'user_id', 'start_city_id', 'end_city_id']);
        return (new WayBillLogic())->addSubscription($data);
    }

    /**
     * 获取订阅路线列表
     * @param $data
     * @return mixed
     * @throws \App\Exceptions\RequestFailException
     */
    public function getSubList($data)
    {
        $data = pick_array($data, ['page', 'user_id']);
        ValidateWayBill::checkValidate($data, ['page', 'user_id']);
        return (new WayBillLogic())->getSubList($data);
    }

    public function delSubById($data)
    {
        $data = pick_array($data, ['user_id', 'id']);
        ValidateWayBill::checkValidate($data, ['user_id', 'id']);
        return (new WayBillLogic())->delSubById($data);
    }

    /**
     * 根据user_id获取个人信息与车辆
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function getPrivateAndCar($data)
    {
        $data = pick_array($data, ['user_id']);
        ValidateWayBill::checkValidate($data, ['user_id']);
        return (new WayBillLogic())->getPrivateAndCar($data);
    }

    /**
     * 运单列表
     * @return array
     */
    public function wayBillOwnerList($data){
        $data = pick_array($data, ['type','user_id']);
        ValidateWayBill::checkValidate($data, ['type','user_id']);
        return (new WayBillLogic())->wayBillOwnerList($data);
    }

    public function createEntrust($data){
        $data = pick_array($data, ['start_addr','end_addr','start_time','end_time','car_card','driver','phone','user_id','start_province_id','start_city_id','start_county_id','end_province_id','end_city_id','end_county_id']);
        ValidateWayBill::checkValidate($data, ['phone','start_time','end_time']);
        return (new WayBillLogic())->createEntrust($data);
    }

    public function cancelWayBill($data){
        $data = pick_array($data, ['waybill_id','create_ip','user_id']);
        ValidateWayBill::checkValidate($data, ['waybill_id']);
        return (new WayBillLogic())->cancelWayBill($data);
    }

    public function companyWayBillList($data){
        $data = pick_array($data, ['type','user_id']);
        ValidateWayBill::checkValidate($data, ['type','user_id']);
        return (new WayBillLogic())->companyWayBillList($data);
    }

    /**
     * 后台运单列表
     * @return array
     */
    public function waybillList($data){
        $data = pick_array($data, ['keywords']);
        return (new WayBillLogic())->waybillList($data);
    }
    /**
     * 取消委托
     * @return array
     */
    public function cancelEntrust($data){
        $data = pick_array($data, ['id']);
        ValidateWayBill::checkValidate($data, ['id']);
        return (new WayBillLogic())->cancelEntrust($data);
    }

    /**
     * 委托详情
     * @return array
     */
    public function entrustDetail($data){
        $data = pick_array($data, ['id']);
        ValidateWayBill::checkValidate($data, ['id']);
        return (new WayBillLogic())->entrustDetail($data);
    }

    /**
     * 修改委托
     * @return array
     */
    public function updateEntrust($data){
        $data = pick_array($data, ['id','start_province_id','start_city_id','start_county_id','end_province_id','end_city_id','end_county_id','start_addr','end_addr','start_time','end_time','car_card','remark']);
        ValidateWayBill::checkValidate($data, ['id']);
        return (new WayBillLogic())->updateEntrust($data);
    }

    /**
     * 委托列表
     * @return array
     */
    public function entrustList($data){
        $data = pick_array($data, ['type','user_id']);
        ValidateWayBill::checkValidate($data, ['type','user_id']);
        return (new WayBillLogic())->entrustList($data);
    }

    /**
     * 修改运单
     * @return array
     */
    public function updateWayBill($data){
        $data = pick_array($data, [
            'id',
            'start_province_id',
            'start_city_id',
            'start_county_id',
            'end_province_id',
            'end_city_id',
            'end_county_id',
            'start_addr',
            'start_addr_detail',
            'end_addr',
            'end_addr_detail',
            'receiver_name',
            'receiver_phone',
            'type',
            'weight',
            'volume',
            'price',
            'loading_time',
            'remark'
        ]);
        ValidateWayBill::checkValidate($data, ['start_addr','end_addr','receiver_name','receiver_phone','type','weight','volume','price','loading_time']);
        return (new WayBillLogic())->updateWayBill($data);
    }

    /**
     * 举报投诉
     * @return array
     */
    public function createComplain($data){
        $data = pick_array($data, ['number','status','remark','upload1','upload2','upload3','waybill_status','waybill_id']);
        ValidateWayBill::checkValidate($data, ['remark']);
        return (new WayBillLogic())->createComplain($data);
    }

    /**
     * 举报详情
     * @return array
     */
    public function complainDetail($data){
        $data = pick_array($data, ['number']);
        ValidateWayBill::checkValidate($data, ['number']);
        return (new WayBillLogic())->complainDetail($data);
    }

    /**
     * 用户是否同意投诉处理结果
     * @return array
     */
    public function complainDeal($data){
        $data = pick_array($data, ['id','status','result','create_ip']);
        ValidateWayBill::checkValidate($data, ['id']);
        return (new WayBillLogic())->complainDeal($data);
    }

    /**
     * 确定装车
     * @return array
     */
    public function truckLoading($data){
        $data = pick_array($data, ['id','role_ids']);
        ValidateWayBill::checkValidate($data, ['id']);
        return (new WayBillLogic())->truckLoading($data);
    }

    /**
     * 完成卸货
     * @return array
     */
    public function truckUnload($data){
        $data = pick_array($data, ['id','code','upload1','upload2','upload3']);
        ValidateWayBill::checkValidate($data, ['id']);
        return (new WayBillLogic())->truckUnload($data);
    }

    /**
     * 运单支付
     * @param $data
     * @return mixed
     * @throws \App\Exceptions\RequestFailException
     */
    public function pay($data)
    {
        $data = pick_array($data, ['id', 'user_id', 'pay_password', 'create_ip']);
        ValidateWayBill::checkValidate($data, ['id', 'user_id','pay_password', 'create_ip']);
        return (new WayBillLogic())->pay($data);
    }

    /**
     * 确认到达
     * @param $data
     * @return mixed
     * @throws \App\Exceptions\RequestFailException
     */
    public function arrive($data)
    {
        $data = pick_array($data, ['id', 'role_ids', 'create_ip']);
        ValidateWayBill::checkValidate($data, ['id', 'create_ip']);
        return (new WayBillLogic())->arrive($data);
    }

    public function payDeposit($data)
    {
        $data = pick_array($data, ['user_id', 'id', 'pay_password', 'create_ip']);
        ValidateWayBill::checkValidate($data, ['user_id', 'id', 'pay_password', 'create_ip']);
        return (new WayBillLogic())->payDeposit($data);
    }

    /**
     * 后台获取运单详情
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function waybillInfo($data)
    {
        $data = pick_array($data, ['id']);
        ValidateWayBill::checkValidate($data, ['id']);
        return (new WayBillLogic())->waybillInfo($data);
    }

    /**
     * 委托统计
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function entrustStatistics($data)
    {
        $data = pick_array($data, ['user_id','start_time','end_time','driver','car_card','type','page']);
        ValidateWayBill::checkValidate($data, ['user_id']);
        return (new WayBillLogic())->entrustStatistics($data);
    }

    //根据车牌号查找对应的司机
    public function companyByNumber($data){
        $data = pick_array($data, ['number','user_id']);
        ValidateWayBill::checkValidate($data, ['number','user_id']);
        return (new WayBillLogic())->companyByNumber($data);
    }

    //委托拒绝接单
    public function entrustRefuse($data){
        $data = pick_array($data, ['id']);
        ValidateWayBill::checkValidate($data, ['id']);
        return (new WayBillLogic())->entrustRefuse($data);
    }

    //通话记录
    public function createRecord($data){
        $data = pick_array($data, ['cargo_id','user_id','type']);
        ValidateWayBill::checkValidate($data, ['user_id']);
        return (new WayBillLogic())->createRecord($data);
    }

    //记录列表
    public function recordList($data){
        $data = pick_array($data, ['user_id','type']);
        ValidateWayBill::checkValidate($data, ['user_id']);
        return (new WayBillLogic())->recordList($data);
    }

    //清空记录
    public function deleteRecord($data){
        $data = pick_array($data, ['user_id']);
        ValidateWayBill::checkValidate($data, ['user_id']);
        return (new WayBillLogic())->deleteRecord($data);
    }
}
